#!/bin/bash
################################## 注意事项 ######################
# daemon.json 配置镜像的资源路径data-root的值，eg:/storage/docker/data
# docker info | grep "Docker Root Dir" 查看路径
# 暂停 docker  sudo systemctl stop docker | sudo systemctl stop docker.socket
# 迁移文件 cp -ra /var/lib/docker/* /storage/docker/data/
# 重新启动 sudo systemctl daemon-reload | sudo systemctl start docker
# docker info | grep "Docker Root Dir" 查看路径是否被替换掉
# 删除文件(依据实际内存情况) rm -rf /var/lib/docker
#################################################################
rpm -q yum &>/dev/null
if [ $? -ne 0 ]; then
    echo "请先安装yum工具"
    exit
fi
rpm -q wget &>/dev/null
if [ $? -ne 0 ]; then
    yum install wget -y
fi
rpm -q yum-utils &>/dev/null
if [ $? -ne 0 ]; then
    yum install yum-utils -y
fi
#更换为阿里云：
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
#或者下载镜像
#wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
#安装社区版
yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
#设置开机启动
systemctl enable docker
#启动docker
systemctl start docker
#设置镜像
if [ ! -d "/etc/docker" ]; then
    mkdir -p  /etc/docker
fi

tee /etc/docker/daemon.json <<-'EOF'
{
    "registry-mirrors": [
     "https://docker.m.daocloud.io",
     "https://docker.imgdb.de",
     "https://docker-0.unsee.tech",
     "https://docker.hlmirror.com",
     "https://docker.1ms.run",
     "https://func.ink",
     "https://lispy.org",
     "https://docker.xiaogenban1993.com",
     "https://docker.xuanyuan.me",
	 "http://docker.zhai.cm",
     "https://docker.registry.cyou",
     "https://docker-cf.registry.cyou",
     "https://dockercf.jsdelivr.fyi",
     "https://docker.jsdelivr.fyi",
     "https://dockertest.jsdelivr.fyi",
     "https://mirror.aliyuncs.com",
     "https://dockerproxy.com",
     "https://mirror.baidubce.com",
     "https://docker.nju.edu.cn",
     "https://docker.mirrors.sjtug.sjtu.edu.cn",
     "https://docker.mirrors.ustc.edu.cn",
     "https://mirror.iscas.ac.cn",
     "https://docker.rainbond.cc",
     "http://noohub.ru",
     "http://docker.nastool.de",
     "http://hub.docker-ttc.xyz",
     "http://freeno.xyz",
     "http://docker.hpcloud.cloud",
     "http://dislabaiot.xyz",
     "http://docker.wget.at",
     "http://lynn520.xyz",
     "http://dockerproxy.com",
     "http://hub.xdark.top",
     "http://hub.yuzuha.cc",
     "http://docker.nat.tf",
     "http://hub.firefly.store",
     "http://hub.littlediary.cn",
     "http://ccr.ccs.tencentyun.com",
     "http://docker.kejilion.pro",
     "http://registry.dockermirror.com",
     "http://docker.mrxn.net",
     "http://dhub.kubesre.xyz",
     "http://docker.hlyun.org",
     "http://hub.rat.dev",
     "http://dockerproxy.cn",
     "http://dockerpull.org",
     "http://hub.xdark.top",
     "http://hub.littlediary.cn",
     "http://docker.udayun.com",
     "http://docker.1panel.dev",
     "http://docker.fxxk.dedyn.io",
     "http://docker.xn--6oq72ry9d5zx.cn",
     "http://docker.m.daocloud.io",
     "http://a.ussh.net",
     "http://docker.zhai.cm"
    ],
    "data-root": "/storage/docker/data"
}
EOF
# 重新启动
systemctl daemon-reload && sudo systemctl restart docker
# 拉取一个测试镜像
docker pull hello-world
# 查看镜像
docker image ls -a